/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VirtualKeyboard.java
 *
 * Created on Jan 19, 2010, 2:07:34 AM
 */

package org.acmwustl.bubble.gui.keyboards;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import org.acmwustl.bubble.controllers.VirtualKeyboardInterface;

/**
 *
 * @author tyler
 */
public class DeprecatedVirtualKeyboard extends javax.swing.JFrame {

    VirtualKeyboardInterface virtualKeyboardInterface;
    
    /** Creates new form VirtualKeyboard */
    public DeprecatedVirtualKeyboard() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        alphaKeys = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        qBtn = new javax.swing.JButton();
        wBtn = new javax.swing.JButton();
        eBtn = new javax.swing.JButton();
        rBtn = new javax.swing.JButton();
        tBtn = new javax.swing.JButton();
        yBtn = new javax.swing.JButton();
        uBtn = new javax.swing.JButton();
        iBtn = new javax.swing.JButton();
        oBtn = new javax.swing.JButton();
        pBtn = new javax.swing.JButton();
        bkspc = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        aBtn = new javax.swing.JButton();
        sBtn = new javax.swing.JButton();
        dBtn = new javax.swing.JButton();
        fBtn = new javax.swing.JButton();
        gBtn = new javax.swing.JButton();
        hBtn = new javax.swing.JButton();
        jBtn = new javax.swing.JButton();
        kBtn = new javax.swing.JButton();
        lBtn = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        zBtn = new javax.swing.JButton();
        xBtn = new javax.swing.JButton();
        cBtn = new javax.swing.JButton();
        vBtn = new javax.swing.JButton();
        bBtn = new javax.swing.JButton();
        nBtn = new javax.swing.JButton();
        mBtn = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        space = new javax.swing.JButton();
        shiftBtn = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);

        jPanel1.setLayout(new java.awt.GridLayout(1, 0));

        qBtn.setText("Q");
        alphaKeys.add(qBtn);
        jPanel1.add(qBtn);

        wBtn.setText("W");
        alphaKeys.add(wBtn);
        jPanel1.add(wBtn);

        eBtn.setText("E");
        alphaKeys.add(eBtn);
        jPanel1.add(eBtn);

        rBtn.setText("R");
        alphaKeys.add(rBtn);
        jPanel1.add(rBtn);

        tBtn.setText("T");
        alphaKeys.add(tBtn);
        jPanel1.add(tBtn);

        yBtn.setText("Y");
        alphaKeys.add(yBtn);
        jPanel1.add(yBtn);

        uBtn.setText("U");
        alphaKeys.add(uBtn);
        jPanel1.add(uBtn);

        iBtn.setText("I");
        alphaKeys.add(iBtn);
        jPanel1.add(iBtn);

        oBtn.setText("O");
        alphaKeys.add(oBtn);
        jPanel1.add(oBtn);

        pBtn.setText("P");
        alphaKeys.add(pBtn);
        jPanel1.add(pBtn);

        bkspc.setText("<");
        jPanel1.add(bkspc);

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        aBtn.setText("A");
        alphaKeys.add(aBtn);
        jPanel2.add(aBtn);

        sBtn.setText("S");
        alphaKeys.add(sBtn);
        jPanel2.add(sBtn);

        dBtn.setText("D");
        alphaKeys.add(dBtn);
        jPanel2.add(dBtn);

        fBtn.setText("F");
        alphaKeys.add(fBtn);
        jPanel2.add(fBtn);

        gBtn.setText("G");
        alphaKeys.add(gBtn);
        jPanel2.add(gBtn);

        hBtn.setText("H");
        alphaKeys.add(hBtn);
        jPanel2.add(hBtn);

        jBtn.setText("J");
        alphaKeys.add(jBtn);
        jPanel2.add(jBtn);

        kBtn.setText("K");
        alphaKeys.add(kBtn);
        jPanel2.add(kBtn);

        lBtn.setText("L");
        alphaKeys.add(lBtn);
        jPanel2.add(lBtn);

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        zBtn.setText("Z");
        alphaKeys.add(zBtn);
        jPanel3.add(zBtn);

        xBtn.setText("X");
        alphaKeys.add(xBtn);
        jPanel3.add(xBtn);

        cBtn.setText("C");
        alphaKeys.add(cBtn);
        jPanel3.add(cBtn);

        vBtn.setText("V");
        alphaKeys.add(vBtn);
        jPanel3.add(vBtn);

        bBtn.setText("B");
        alphaKeys.add(bBtn);
        jPanel3.add(bBtn);

        nBtn.setText("N");
        alphaKeys.add(nBtn);
        jPanel3.add(nBtn);

        mBtn.setText("M");
        alphaKeys.add(mBtn);
        jPanel3.add(mBtn);

        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        space.setText("SPACE");
        jPanel4.add(space);

        shiftBtn.setSelected(true);
        shiftBtn.setText("SHIFT");
        shiftBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shiftBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 489, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 628, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(shiftBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 760, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(shiftBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel1, jPanel2, jPanel3, jPanel4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void shiftBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shiftBtnActionPerformed
        if(shiftBtn.isSelected()) {
            Enumeration em = alphaKeys.getElements();
            while(em.hasMoreElements()) {
                JButton b = (JButton)em.nextElement();
                b.setText(b.getText().toUpperCase());
            }
        }
        else {
            Enumeration em = alphaKeys.getElements();
            while(em.hasMoreElements()) {
                JButton b = (JButton)em.nextElement();
                b.setText(b.getText().toLowerCase());
            }
        }
    }//GEN-LAST:event_shiftBtnActionPerformed

    private void addActionListeners() {
        Enumeration em = alphaKeys.getElements();
        while(em.hasMoreElements()) {
            JButton b = (JButton)em.nextElement();
            b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JButton me = (JButton) e.getSource();
                    virtualKeyboardInterface.receieveCharacter(me.getText().charAt(0));
                }
            });
        }

        space.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                virtualKeyboardInterface.receieveCharacter(' ');
            }
        });

        bkspc.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                virtualKeyboardInterface.receieveCharacter('<');
            }
        });
    }

    public VirtualKeyboardInterface getVirtualKeyboardInterface() {
        return virtualKeyboardInterface;
    }

    public void setVirtualKeyboardInterface(VirtualKeyboardInterface virtualKeyboardInterface) {
        this.virtualKeyboardInterface = virtualKeyboardInterface;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aBtn;
    private javax.swing.ButtonGroup alphaKeys;
    private javax.swing.JButton bBtn;
    private javax.swing.JButton bkspc;
    private javax.swing.JButton cBtn;
    private javax.swing.JButton dBtn;
    private javax.swing.JButton eBtn;
    private javax.swing.JButton fBtn;
    private javax.swing.JButton gBtn;
    private javax.swing.JButton hBtn;
    private javax.swing.JButton iBtn;
    private javax.swing.JButton jBtn;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JButton kBtn;
    private javax.swing.JButton lBtn;
    private javax.swing.JButton mBtn;
    private javax.swing.JButton nBtn;
    private javax.swing.JButton oBtn;
    private javax.swing.JButton pBtn;
    private javax.swing.JButton qBtn;
    private javax.swing.JButton rBtn;
    private javax.swing.JButton sBtn;
    private javax.swing.JToggleButton shiftBtn;
    private javax.swing.JButton space;
    private javax.swing.JButton tBtn;
    private javax.swing.JButton uBtn;
    private javax.swing.JButton vBtn;
    private javax.swing.JButton wBtn;
    private javax.swing.JButton xBtn;
    private javax.swing.JButton yBtn;
    private javax.swing.JButton zBtn;
    // End of variables declaration//GEN-END:variables

}
